'use strict';
import React from 'react';
import {
    HttpService,
    Toast
} from '../utils'
import {
    connect
} from 'react-redux';
import {
    bindActionCreators
} from 'redux';
import WxServer from '../wx/WxServer'


class Test extends React.Component {
    static contextTypes = {
        router: React.PropTypes.object.isRequired
    };

    constructor(props) {
        super(props)
    }
    componentDidMount() {
        WxServer.init();
        wx.onVoiceRecordEnd({
            complete: function(res) {
                sessionStorage.localId = res.localId;
                //Toast.toast('onVoiceRecordEnd')
            }
        });
    }

    wxstart() {
        wx.startRecord();
    }
    wxend() {
        wx.stopRecord({
            success: function(res) {
                sessionStorage.localId = res.localId;
            }
        });
    }
    wxbo() {
        Toast.toast(sessionStorage.localId)
        wx.playVoice({
            localId: sessionStorage.localId // 需要播放的音频的本地ID，由stopRecord接口获得
        });
    }
    wxdown() {
        Toast.toast(sessionStorage.localId)
        wx.playVoice({
            localId: sessionStorage.localId // 需要播放的音频的本地ID，由stopRecord接口获得
        });
    }

    render() {
        return (
            <div style={{fontSize:'30px'}}>
                <br /><br />
                <button style={{width:'100%'}} onClick={this.wxstart.bind(this)}>开始录音</button><br /><br />
                <button style={{width:'100%'}} onClick={this.wxend.bind(this)}>结束录音</button><br /><br />
                <button style={{width:'100%'}} onClick={this.wxbo.bind(this)}>播放录音</button><br /><br />
                <button style={{width:'100%'}} onClick={this.wxdown.bind(this)}>下载录音</button>
            </div>
        )
    }
}
const mapStateToProps = state => {
    return {};
};
const mapDispatchToProps = (dispatch) => {
    return bindActionCreators({}, dispatch);
};
export default connect(mapStateToProps, mapDispatchToProps)(Test);
